const mysql = require("mysql");
const config = require('../config/mysql.config')
const connect =  mysql.createConnection({
    host     : 'localhost',
    port     : '3306',
    user     : 'root',
    password : 'root',
    database : 'project',
    ...config
});
connect.connect();
const createMysql = () => async (ctx,next) => {
    ctx.searchQuery = (query) => {
        return new Promise((resolve,reject) => {
            connect.query(query, function (error, results, fields) {
                if (error){
                    reject(error);
                    return;
                };
                resolve(results);
            });
        })
       
    }
    await next();
}

module.exports = createMysql;